﻿using ElectronicShoppingMall.Service.Models.Enterprise;
using ElectronicShoppingMall.Service.Services.Enterprise;
using Extension;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Filters;

namespace ElectronicShoppingMall.Web.Back.Filter
{
    public class OperationLogAttribute : ActionFilterAttribute

    {
        public string OperatDetail { get; set; }


        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            bool result = true;
            if (actionExecutedContext.Exception != null)
            {
                result = false;
            }
            OperationLogService _service = new OperationLogService();
            string auth = actionExecutedContext.Request.Headers.Authorization.ToString();
            AdminLogModel log = new AdminLogModel
            {
                EmployeeId = ExtensionMethods.GetEmployeeUserObject(auth).EmployeeId,
                OperatDetail = OperatDetail,
                Result = result
            };
            _service.CreateLog(log);
        }
    }
}